#!/bin/sh

BACKUP_SERVER="172.16.3.111"

RESTORE_SERVER="
192.168.20.112
"

DATE=`date +%Y%m%d_%H`

PASSWD="rpaqlf"

db_backup()
{
sshpass -p $PASSWD ssh gamevil@$BACKUP_SERVER "
chmod +x resource_tmp.sh
./resource_tmp.sh
rm resource_tmp.sh
rm resource_tmp.txt
"
}

sftp_get()
{
sshpass -p $PASSWD sftp gamevil@$BACKUP_SERVER <<EOF
bi
ha
get resource_table.sql
rm resource_table.sql
exit
EOF
}

sftp_put()
{
sshpass -p $PASSWD sftp -P gamevil@$1 <<EOF
bi
ha
cd /home/gamevil/db_restore;
mput resource_table.sql
exit
EOF
}

db_restore()
{
sshpass -p xkdlfpshf ssh -p 1818 gamevil@$1 "
mysql -ugamevil -pvlwlrpaqlf pz_user < resource_table.sql
rm resource_table.sql
"
}

sshpass -p rpaqlf scp resource_tmp.sh gamevil@$BACKUP_SERVER:resource_tmp.sh
sshpass -p rpaqlf scp resource_tmp.txt gamevil@$BACKUP_SERVER:resource_tmp.txt

db_backup

sftp_get

for ip in $RESTORE_SERVER
do
#sftp_put $ip
sshpass -p xkdlfpshf scp -P 1818 resource_table.sql gamevil@$ip:resource_table.sql
db_restore $ip
done


